﻿using System;
using Microsoft.EntityFrameworkCore.Migrations;

#nullable disable

namespace GroupSix.Api.Migrations
{
    /// <inheritdoc />
    public partial class AddArticleTables : Migration
    {
        /// <inheritdoc />
        protected override void Up(MigrationBuilder migrationBuilder)
        {
            migrationBuilder.CreateTable(
                name: "gs_article_categories",
                columns: table => new
                {
                    Id = table.Column<Guid>(type: "uuid", nullable: false),
                    Name = table.Column<string>(type: "character varying(100)", maxLength: 100, nullable: false),
                    Description = table.Column<string>(type: "character varying(500)", maxLength: 500, nullable: false),
                    ParentId = table.Column<Guid>(type: "uuid", nullable: true),
                    Level = table.Column<int>(type: "integer", nullable: false),
                    SortOrder = table.Column<int>(type: "integer", nullable: false),
                    Code = table.Column<string>(type: "text", nullable: true),
                    IsActive = table.Column<bool>(type: "boolean", nullable: false),
                    IsDeleted = table.Column<bool>(type: "boolean", nullable: false),
                    CreatedAt = table.Column<DateTime>(type: "timestamp with time zone", nullable: false),
                    UpdatedAt = table.Column<DateTime>(type: "timestamp with time zone", nullable: false),
                    CreatedBy = table.Column<Guid>(type: "uuid", nullable: false),
                    UpdatedBy = table.Column<Guid>(type: "uuid", nullable: false),
                    DisplayOrder = table.Column<int>(type: "integer", nullable: false),
                    Remarks = table.Column<string>(type: "text", nullable: true)
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_gs_article_categories", x => x.Id);
                    table.ForeignKey(
                        name: "FK_gs_article_categories_gs_article_categories_ParentId",
                        column: x => x.ParentId,
                        principalTable: "gs_article_categories",
                        principalColumn: "Id",
                        onDelete: ReferentialAction.Restrict);
                });

            migrationBuilder.CreateTable(
                name: "gs_articles",
                columns: table => new
                {
                    Id = table.Column<Guid>(type: "uuid", nullable: false),
                    Title = table.Column<string>(type: "character varying(200)", maxLength: 200, nullable: false),
                    Content = table.Column<string>(type: "text", nullable: false),
                    Summary = table.Column<string>(type: "character varying(500)", maxLength: 500, nullable: false),
                    CategoryId = table.Column<Guid>(type: "uuid", nullable: false),
                    CategoryName = table.Column<string>(type: "character varying(100)", maxLength: 100, nullable: false),
                    Tags = table.Column<string>(type: "character varying(500)", maxLength: 500, nullable: false),
                    Status = table.Column<string>(type: "character varying(20)", maxLength: 20, nullable: false),
                    AuthorId = table.Column<Guid>(type: "uuid", nullable: false),
                    AuthorName = table.Column<string>(type: "character varying(50)", maxLength: 50, nullable: false),
                    CoverImage = table.Column<string>(type: "character varying(500)", maxLength: 500, nullable: false),
                    ViewCount = table.Column<int>(type: "integer", nullable: false),
                    LikeCount = table.Column<int>(type: "integer", nullable: false),
                    CommentCount = table.Column<int>(type: "integer", nullable: false),
                    PublishedAt = table.Column<DateTime>(type: "timestamp with time zone", nullable: true),
                    SeoTitle = table.Column<string>(type: "character varying(200)", maxLength: 200, nullable: false),
                    SeoKeywords = table.Column<string>(type: "character varying(500)", maxLength: 500, nullable: false),
                    SeoDescription = table.Column<string>(type: "character varying(1000)", maxLength: 1000, nullable: false),
                    IsTop = table.Column<bool>(type: "boolean", nullable: false),
                    IsRecommend = table.Column<bool>(type: "boolean", nullable: false),
                    SortWeight = table.Column<int>(type: "integer", nullable: false),
                    Code = table.Column<string>(type: "text", nullable: true),
                    IsActive = table.Column<bool>(type: "boolean", nullable: false),
                    IsDeleted = table.Column<bool>(type: "boolean", nullable: false),
                    CreatedAt = table.Column<DateTime>(type: "timestamp with time zone", nullable: false),
                    UpdatedAt = table.Column<DateTime>(type: "timestamp with time zone", nullable: false),
                    CreatedBy = table.Column<Guid>(type: "uuid", nullable: false),
                    UpdatedBy = table.Column<Guid>(type: "uuid", nullable: false),
                    DisplayOrder = table.Column<int>(type: "integer", nullable: false),
                    Remarks = table.Column<string>(type: "text", nullable: true)
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_gs_articles", x => x.Id);
                });

            migrationBuilder.CreateIndex(
                name: "IX_gs_article_categories_Level",
                table: "gs_article_categories",
                column: "Level");

            migrationBuilder.CreateIndex(
                name: "IX_gs_article_categories_ParentId",
                table: "gs_article_categories",
                column: "ParentId");

            migrationBuilder.CreateIndex(
                name: "IX_gs_article_categories_SortOrder",
                table: "gs_article_categories",
                column: "SortOrder");

            migrationBuilder.CreateIndex(
                name: "IX_gs_articles_AuthorId",
                table: "gs_articles",
                column: "AuthorId");

            migrationBuilder.CreateIndex(
                name: "IX_gs_articles_CategoryId",
                table: "gs_articles",
                column: "CategoryId");

            migrationBuilder.CreateIndex(
                name: "IX_gs_articles_CreatedAt",
                table: "gs_articles",
                column: "CreatedAt");

            migrationBuilder.CreateIndex(
                name: "IX_gs_articles_IsRecommend",
                table: "gs_articles",
                column: "IsRecommend");

            migrationBuilder.CreateIndex(
                name: "IX_gs_articles_IsTop",
                table: "gs_articles",
                column: "IsTop");

            migrationBuilder.CreateIndex(
                name: "IX_gs_articles_PublishedAt",
                table: "gs_articles",
                column: "PublishedAt");

            migrationBuilder.CreateIndex(
                name: "IX_gs_articles_SortWeight",
                table: "gs_articles",
                column: "SortWeight");

            migrationBuilder.CreateIndex(
                name: "IX_gs_articles_Status",
                table: "gs_articles",
                column: "Status");
        }

        /// <inheritdoc />
        protected override void Down(MigrationBuilder migrationBuilder)
        {
            migrationBuilder.DropTable(
                name: "gs_article_categories");

            migrationBuilder.DropTable(
                name: "gs_articles");
        }
    }
}
